class Container {
    static of (value) {
        return new Container(value);
    }
    constructor (value) {
        this._value = value;
    }
    map(fn) {
        return Container.of(fn(this._value));
    }
}

class MayBe {
    static of(value) {
        return new MayBe(value);
    }

    constructor(value) {
        this._value = value;
    }

    map(fn) {
        // return MayBe.of(fn(this._value));
        return this.isNothing() ? this : MayBe.of(fn(this._value));
    }
    
    isNothing() {
        return this._value === null || this._value === undefined;
    }
}


const fp = require('lodash/fp');

const ex4 = function (n) {
    if (n) {
        return parseInt(n);
    }
};


const ex4Rerite = function (n) {
    const maybe = MayBe.of(n);
    return maybe.map(parseInt)
};

console.log('ex4', ex4('10.7'));
console.log('ex4Rerite', ex4Rerite('10.7'));

